package org.xg.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName MyServlet2
 * @date 2021/9/23 10:09
 **/
public class MyServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置字符集
        resp.setContentType("text/html;charset=UTF-8");
        //使用PrintWriter.write()方法向前台输出内容
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("Hello World");
        printWriter.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //使用PrintWriter.write()方法向前台输出内容
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("Hello World");
        printWriter.close();
        doGet(req, resp);
    }
}
